﻿#ifndef POST_THREEDIMENSIONGRAPH_H
#define POST_THREEDIMENSIONGRAPH_H

#include <QWidget>
#include "PostWindowBase.h"
#include "FieldGraphGenerator.h"
#include "WidgetCutter.h"
#include <vtkSmartPointer.h>
#include <vtkDelimitedTextReader.h>

QT_BEGIN_NAMESPACE
namespace Ui { class ThreeDimensionDiagraph; };
QT_END_NAMESPACE

class vtkGenericOpenGLRenderWindow;
class vtkCamera;
class vtkRenderer;
class vtkAxesActor;
class vtkDataSet;
class vtkRenderWindow;
class vtkPolyDataMapper;
class vtkPropAssembly;
class vtkDataSetMapper;
class vtkOrientationMarkerWidget;

namespace pst
{
    class NearFieldDataGenerator;
    class FieldGraphGenerator;
    class WidgetCutter;
    class UnstructuredGridReader;
    class TableViewWidget;
    class MutiVTKFilesReader;
}

namespace DataModel
{
    class PostThreeDimensionGraphData;
}

namespace MainWindow
{
    class MainWindow;
}
namespace DataModel
{
    class IdaIGeometrySet;
}

namespace pst
{
    class NearFieldDataGenerator;
    class FarFieldDataGenerator;
    class PostUsualInteractionStyle;

    class ThreeDimensionDiagraph : public PostWindowBase
    {
        Q_OBJECT

    public:
        ThreeDimensionDiagraph(QWidget* parent);
        ~ThreeDimensionDiagraph();

        bool ReadFieldData(QString filePath);


    public slots:
        void on_comboBoxFrequency_currentIndexChanged(int index);
        void on_pushBtnApply_clicked();
        void on_checkBox_normalization_stateChanged(int state);
        void on_checkBox_logarithm_stateChanged(int state);

        void on_pushButton_fitView_clicked();
        void on_btnTopView_clicked();
        void on_btnBottomView_clicked();
        void on_btnFrontView_clicked();
        void on_btnBackView_clicked();
        void on_btnLeftView_clicked();
        void on_btnRightView_clicked();

        void on_lineEditSBTitleString_editingFinished();
        void on_comboBoxSBTitleColor_activated(int index);
        void on_comboBoxSBFontSize_currentIndexChanged(int index);

        void on_checkBoxScalarBarRangeAutomatic_stateChanged(int state);
        void on_doubleSpinBox_SBMinRange_valueChanged(double value);
        void on_doubleSpinBox_SBMaxRange_valueChanged(double value);

        void on_slider_meshTransparency_valueChanged(int value);
        //void on_slider_meshTransparency_sliderReleased();
        void on_slider_ResultTransparency_valueChanged(int value);
        //void on_doubleSpinBox_scaleGraph_valueChanged(int value);
        void on_checkBox_enableSlice_stateChanged(int state);
        void AddCutter();
        void on_comboBox_sliceDirection_currentIndexChanged(int index);
        void on_comboBox_slicePosition_currentIndexChanged(int index);
        void on_pb_exportData_clicked();
        void on_doubleSpinBox_resultScale_valueChanged(double value);

        /// @brief  刷新窗口标题
        /// @param caseID 算例ID
        /// @param resultType 查看结果类型BaseModul::ResultType
        /// @param viewResultDataID 查看结果数据ID
        void slot_refreshWindowTitle(int caseID, int resultType, int viewResultDataID);

    private:
        QString generateFilePath(const QString& fileName, int index);
        QList<QString> getFreqFromSetting();
        bool readerDelimitedTextFromLocal(const QString& fileName);
        void resetCameraViewDirection(vtkCamera* camera, double look_x,
            double look_y, double look_z, double up_x, double up_y, double up_z);
        void copyActor(vtkActor* sourceActor, vtkSmartPointer<vtkActor> desActor);
        void setScalarBarRange();
        void initUI();
        void checkDataType(const QString& filePath);
        void decideLogFactory();
        /// @brief 
        void setLogNormalButtonState(bool state);
        void setSlicePositionButtonState();
        bool readData(const QString& filePath);
        void generateResultActor();
        void InitDefaultLookupTable();
        void initScalarBarPipeLine();
        void activeButtonAfterReadData();
        void generateSlicePosition(int index);
        //void writeMOMData();
        void readDataFromDataManager();
        void restoreLogic();
        //void importPreProcessWindowData();
    private:
        Ui::ThreeDimensionDiagraph* ui;

        /// @brief 数据类型 
        /// 0：360*360.txt 远场
        /// 1: 4列.txt 近场
        /// 2: .vtk数据
        int m_dataType;

        vtkSmartPointer<vtkActor> m_dataActor;
        //vtkSmartPointer<vtkGenericOpenGLRenderWindow> m_renderWindow3D;
        vtkSmartPointer<vtkRenderWindow> m_renderWindow3D;
        vtkSmartPointer<vtkRenderWindowInteractor> m_interactor;
        vtkSmartPointer<vtkRenderer> m_render3D;
        std::shared_ptr <pst::WidgetCutter> m_widgetCutter;
        std::shared_ptr < pst::MutiVTKFilesReader> m_mutiReader;
        //std::shared_ptr <pst::FieldGraphGenerator> m_fieldGraphGenerator;
        //int m_caseID;
        //int m_iD;
        vtkSmartPointer<vtkAxesActor> m_leftDownCornerAxes;
        vtkSmartPointer<vtkOrientationMarkerWidget> m_leftDownCornerWidget;
        //int m_viewResultDataID;
        vtkSmartPointer<vtkDataSet> m_dataSet;
        vtkSmartPointer<vtkDataSetMapper> m_dataMapper;

        vtkSmartPointer<vtkScalarBarActor> m_scalarBarActor;
        vtkSmartPointer<vtkScalarBarWidget> m_scalarBarWidget;
        vtkSmartPointer<vtkLookupTable> m_lookupTable;
        double m_scalarBarAutoDataRange[2];

        vtkSmartPointer<vtkDelimitedTextReader> m_delimitedTextReader;
        vtkTable* m_originalTable;
        vtkTable* logTable;
        bool m_shouldLogTheData;
        bool m_shouldNormalizeTheData;

        FarFieldDataGenerator* m_farFieldDataGenerator;
        NearFieldDataGenerator* m_nearFieldDataGenerator;

        //QString m_fileName;
        bool m_isReadDataSuc;
        QString m_scalarBarTitle;

        bool m_isCutterAdded;
        DataModel::PostThreeDimensionGraphData* m_gain3DData;

        vtkSmartPointer<vtkDataSet> m_cutterInputData;
        vtkSmartPointer<vtkPolyData> m_emptyData;

        QList<vtkSmartPointer<vtkActor>> m_preWDmeshActorsList;
        QString m_filePathToRead;
        /// @brief 原始数据R的范围
        double m_originalRRange[2];
        double m_logDefautFactory;
        /// @brief 取对数后R的范围
        double m_logDataRRange[2];
    };
}
#endif
